home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / libdemo / trackball.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  76 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * trackball.h
  19.  * A virtual trackball implementation
  20.  * Written by Gavin Bell for Silicon Graphics, November 1988.
  21.  */
  22.  
  23. #include "vect.h"
  24.  
  25. /*
  26.  * Pass the x and y coordinates of the last and current positions of
  27.  * the mouse, scaled so they are from (-1.0 ... 1.0).
  28.  *
  29.  * if ox,oy is the window's center and sizex,sizey is its size, then
  30.  * the proper transformation from screen coordinates (sc) to world
  31.  * coordinates (wc) is:
  32.  * wcx = (2.0 * (scx-ox)) / (float)sizex - 1.0
  33.  * wcy = (2.0 * (scy-oy)) / (float)sizey - 1.0
  34.  *
  35.  * The resulting rotation is returned as a quaternion rotation in the
  36.  * first paramater.
  37.  */
  38. void
  39. trackball(float q[4], float p1x, float p1y, float p2x, float p2y);
  40.  
  41. /*
  42.  * Given two quaternions, add them together to get a third quaternion.
  43.  * Adding quaternions to get a compound rotation is analagous to adding
  44.  * translations to get a compound translation.  When incrementally
  45.  * adding rotations, the first argument here should be the new
  46.  * rotation, the second and third the total rotation (which will be
  47.  * over-written with the resulting new total rotation).
  48.  */
  49. void
  50. add_quats(float *q1, float *q2, float *dest);
  51.  
  52. /*
  53.  * A useful function, builds a rotation matrix in Matrix based on
  54.  * given quaternion.
  55.  */
  56. void
  57. build_rotmatrix(float m[4][4], float q[4]);
  58.  
  59. /*
  60.  * This function computes a quaternion based on an axis (defined by
  61.  * the given vector) and an angle about which to rotate.  The angle is
  62.  * expressed in radians.  The result is put into the third argument.
  63.  */
  64. void
  65. axis_to_quat(float a[3], float angle, float q[4]);
  66.  
  67. /*
  68.  * These are defined for compatibility with an older version of this
  69.  * that referred to quaternions as 'Euler Paramaters'.  The term
  70.  * 'quaternion' is much more widely used in the computer graphics
  71.  * community, and causes less confusion (Euler Paramaters are easily
  72.  * confused with Euler Angles, which are totally different).
  73.  */
  74. #define add_eulers add_quats
  75. #define axis_to_euler axis_to_quat
  76.